﻿using System;
using System.Data;
using System.Text;
using System.Data.OleDb;
using DBUtility;
namespace candi
{
    /// <summary>
    /// 类Feedback。
    /// </summary>
    [Serializable]
    public partial class FeedbackDBModel
    {
        public FeedbackDBModel()
        { }
        #region Model
        private int _id;
        private string _buyerid;
        private string _itemname;
        private string _itemno;
        private string _price;
        private string _store;
        private DateTime _saleDate;

        private string _r1 = string.Empty;
        private string _r2 = string.Empty;
        /// <summary>
        /// 
        /// </summary>
        public int ID
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string BuyerID
        {
            set { _buyerid = value; }
            get { return _buyerid; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string ItemName
        {
            set { _itemname = value; }
            get { return _itemname; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string ItemNo
        {
            set { _itemno = value; }
            get { return _itemno; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Price
        {
            set { _price = value; }
            get { return _price; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Store
        {
            set { _store = value; }
            get { return _store; }
        }
        public DateTime SaleDate
        {
            get { return _saleDate; }
            set { _saleDate = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string r1
        {
            set { _r1 = value; }
            get { return _r1; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string r2
        {
            set { _r2 = value; }
            get { return _r2; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FeedbackDBModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,BuyerID,ItemName,ItemNo,Price,Store,r1,r2 ");
            strSql.Append(" FROM [Feedback] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    this.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BuyerID"] != null && ds.Tables[0].Rows[0]["BuyerID"].ToString() != "")
                {
                    this.BuyerID = ds.Tables[0].Rows[0]["BuyerID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ItemName"] != null && ds.Tables[0].Rows[0]["ItemName"].ToString() != "")
                {
                    this.ItemName = ds.Tables[0].Rows[0]["ItemName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ItemNo"] != null && ds.Tables[0].Rows[0]["ItemNo"].ToString() != "")
                {
                    this.ItemNo = ds.Tables[0].Rows[0]["ItemNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Price"] != null && ds.Tables[0].Rows[0]["Price"].ToString() != "")
                {
                    this.Price = ds.Tables[0].Rows[0]["Price"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Store"] != null && ds.Tables[0].Rows[0]["Store"].ToString() != "")
                {
                    this.Store = ds.Tables[0].Rows[0]["Store"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SaleDate"] != null && ds.Tables[0].Rows[0]["SaleDate"].ToString() != "")
                {
                    this.SaleDate = DateTime.Parse(ds.Tables[0].Rows[0]["SaleDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["r1"] != null && ds.Tables[0].Rows[0]["r1"].ToString() != "")
                {
                    this.r1 = ds.Tables[0].Rows[0]["r1"].ToString();
                }
                if (ds.Tables[0].Rows[0]["r2"] != null && ds.Tables[0].Rows[0]["r2"].ToString() != "")
                {
                    this.r2 = ds.Tables[0].Rows[0]["r2"].ToString();
                }
            }
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [Feedback]");
            strSql.Append(" where ID=@ID ");

            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            return DbHelperOleDb.Exists(strSql.ToString(), parameters);
        }
        public bool Exists(string cond)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [Feedback]");
            if (cond.Length > 0)
            {
                strSql.Append(" where   " + cond);
            }


            return DbHelperOleDb.Exists(strSql.ToString());
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [Feedback] (");
            strSql.Append("BuyerID,ItemName,ItemNo,Price,Store,r1,r2)");
            strSql.Append(" values (");
            strSql.Append("@BuyerID,@ItemName,@ItemNo,@Price,@Store,@r1,@r2)");
            OleDbParameter[] parameters = {
					new OleDbParameter("@BuyerID", OleDbType.VarChar,255),
					new OleDbParameter("@ItemName", OleDbType.VarChar,255),
					new OleDbParameter("@ItemNo", OleDbType.VarChar,255),
					new OleDbParameter("@Price", OleDbType.VarChar,255),
					new OleDbParameter("@Store", OleDbType.VarChar,255),
					new OleDbParameter("@r1", OleDbType.VarChar,255),
					new OleDbParameter("@r2", OleDbType.VarChar,255),
					new OleDbParameter("@SaleDate",SaleDate)};
            parameters[0].Value = BuyerID;
            parameters[1].Value = ItemName;
            parameters[2].Value = ItemNo;
            parameters[3].Value = Price;
            parameters[4].Value = Store;
            parameters[5].Value = r1;
            parameters[6].Value = r2;

            DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [Feedback] set ");
            strSql.Append("BuyerID=@BuyerID,");
            strSql.Append("ItemName=@ItemName,");
            strSql.Append("ItemNo=@ItemNo,");
            strSql.Append("Price=@Price,");
            strSql.Append("Store=@Store,");
            strSql.Append("SaleDate=@SaleDate,");
            strSql.Append("r1=@r1,");
            strSql.Append("r2=@r2");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@BuyerID", OleDbType.VarChar,255),
					new OleDbParameter("@ItemName", OleDbType.VarChar,255),
					new OleDbParameter("@ItemNo", OleDbType.VarChar,255),
					new OleDbParameter("@Price", OleDbType.VarChar,255),
					new OleDbParameter("@Store", OleDbType.VarChar,255),
					new OleDbParameter("@r1", OleDbType.VarChar),
					new OleDbParameter("@r2", OleDbType.VarChar),
					new OleDbParameter("@ID", OleDbType.Integer,4),
					new OleDbParameter("@SaleDate",SaleDate)};
            parameters[0].Value = BuyerID;
            parameters[1].Value = ItemName;
            parameters[2].Value = ItemNo;
            parameters[3].Value = Price;
            parameters[4].Value = Store;
            parameters[5].Value = r1;
            parameters[6].Value = r2;
            parameters[7].Value = ID;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Feedback] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,BuyerID,ItemName,ItemNo,Price,Store,r1,r2 ");
            strSql.Append(" FROM [Feedback] ");
            strSql.Append(" where ID=@ID ");
            OleDbParameter[] parameters = {
					new OleDbParameter("@ID", OleDbType.Integer,4)};
            parameters[0].Value = ID;

            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    this.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BuyerID"] != null && ds.Tables[0].Rows[0]["BuyerID"].ToString() != "")
                {
                    this.BuyerID = ds.Tables[0].Rows[0]["BuyerID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ItemName"] != null && ds.Tables[0].Rows[0]["ItemName"].ToString() != "")
                {
                    this.ItemName = ds.Tables[0].Rows[0]["ItemName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ItemNo"] != null && ds.Tables[0].Rows[0]["ItemNo"].ToString() != "")
                {
                    this.ItemNo = ds.Tables[0].Rows[0]["ItemNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Price"] != null && ds.Tables[0].Rows[0]["Price"].ToString() != "")
                {
                    this.Price = ds.Tables[0].Rows[0]["Price"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Store"] != null && ds.Tables[0].Rows[0]["Store"].ToString() != "")
                {
                    this.Store = ds.Tables[0].Rows[0]["Store"].ToString();
                }
                if (ds.Tables[0].Rows[0]["SaleDate"] != null && ds.Tables[0].Rows[0]["SaleDate"].ToString() != "")
                {
                    this.SaleDate = DateTime.Parse(ds.Tables[0].Rows[0]["SaleDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["r1"] != null && ds.Tables[0].Rows[0]["r1"].ToString() != "")
                {
                    this.r1 = ds.Tables[0].Rows[0]["r1"].ToString();
                }
                if (ds.Tables[0].Rows[0]["r2"] != null && ds.Tables[0].Rows[0]["r2"].ToString() != "")
                {
                    this.r2 = ds.Tables[0].Rows[0]["r2"].ToString();
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM [Feedback] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperOleDb.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

